#include <stdio.h>
#include <pthread.h>
#include <signal.h>
#include "global.h"
#include "get_input.h"



int speed;
pthread_t run_tid;
pthread_t tid;
extern int dir;
extern pthread_mutex_t dir_mutex;
extern const char * const DirI[4];
void set_speed(void) {
    set_speed:
    printf("\033[2J\n");
    printf("0) 1.0s\n");
    printf("1) 0.8s\n");
    printf("2) 0.6s\n");
    printf("3) 0.4s\n");
    printf("4) 0.2s\n");
    printf(">");
    setbuf(stdin, NULL);
    scanf("%d", &speed);
    if(speed>=0 && speed<5)
        speed = (5-speed) * 200000;
    else
        goto  set_speed;
}


int main(void)
{   
    int cmd;
    register_sus_sig();
    lb_main:
    cmd = -1;
    printf("\033[2J\n");
    printf("\t\tMAIN\n");
    printf("0) Set speed\n");
    printf("1) Start\n");
    printf("2) Exit\n");
    putchar('>');
    setbuf(stdin, NULL);
    scanf("%d", &cmd);
    switch(cmd) {
    case 0:
        set_speed();
        goto lb_main;
    case 1:
        pthread_create(&run_tid, NULL, run, NULL);
        pthread_join(run_tid, (void **)NULL);
        goto lb_main;
    case 2: 
        return 0;
    default :
        goto lb_main; 
    }
}


